﻿/*  ----------------------------------------------------------------------------
 *  Warren Moxley
 *  ----------------------------------------------------------------------------
 *  GoogleHelper
 *  ----------------------------------------------------------------------------
 *  File:       Program.cs
 *  Author:     IT1SERVICES\wmoxley
 *  ----------------------------------------------------------------------------
	Licensed to the Apache Software Foundation (ASF) under one
       	or more contributor license agreements.  See the NOTICE file
       	distributed with this work for additional information
       	regarding copyright ownership.  The ASF licenses this file
       	to you under the Apache License, Version 2.0 (the
       	"License"); you may not use this file except in compliance
       	with the License.  You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

       	Unless required by applicable law or agreed to in writing,
       	software distributed under the License is distributed on an
       	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
       	KIND, either express or implied.  See the License for the
       	specific language governing permissions and limitations
       	under the License. 
 *  ----------------------------------------------------------------------------
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GoogleHelper;
using Google.Apis;
using Google.Apis.Authentication;

namespace TestGoogleHelper
{
    class Program
    {
        static void Main(string[] args)
        {
            Google.Apis.Wrappers.Tasks.TasksService tsSvc = new Google.Apis.Wrappers.Tasks.TasksService(new NullAuthenticator(), "", "GTasksSync");

            string userName = "warrenmoxley@gmail.com";
            string password = "dojamang";

            TaskListHelper tlh = new TaskListHelper(userName, password);
            TaskHelper th = new TaskHelper(userName, password);

            foreach(var translation in TranslateHelper.GetTranslation(LanguageEnum.English, LanguageEnum.Spanish, "Testing Google Translate"))
                Console.WriteLine(LanguageEnum.English.ToString() + ": Testing Google Translate => " + LanguageEnum.Spanish.ToString() + ": " + translation.TranslatedText);

            string pageToken = "";

            Console.WriteLine("Task Lists:");
            var taskLists = tlh.GetTaskLists(pageToken);

            Console.WriteLine(tsSvc.ObjectToJson(taskLists).Replace("{", Environment.NewLine + "{" + Environment.NewLine).Replace("}", Environment.NewLine + "}" + Environment.NewLine).Replace(",", "," + Environment.NewLine));

            foreach (var item in taskLists.Items)
            {
                Console.WriteLine("List Item {Id}: " + item.Id);

                var taskList = tlh.GetTaskList(item.Id);

                Console.WriteLine(tsSvc.ObjectToJson(taskList).Replace("{", Environment.NewLine + "{" + Environment.NewLine).Replace("}", Environment.NewLine + "}" + Environment.NewLine).Replace(",", "," + Environment.NewLine));

                bool bMoreTasks = true;

                while (bMoreTasks)
                {
                    var tasks = th.GetTasks(item.Id, pageToken, true, true, true);

                    Console.WriteLine("Tasks {Etag}: " + tasks.Etag);

                    Console.WriteLine(tsSvc.ObjectToJson(tasks).Replace("{", Environment.NewLine + "{" + Environment.NewLine).Replace("}", Environment.NewLine + "}" + Environment.NewLine).Replace(",", "," + Environment.NewLine));

                    foreach (var task in tasks.Items)
                    {
                        Console.WriteLine("Task {Id}: " + task.Id);

                        var taskItem = th.GetTask(task.Id, item.Id);

                        Console.WriteLine(tsSvc.ObjectToJson(taskItem).Replace("{", Environment.NewLine + "{" + Environment.NewLine).Replace("}", Environment.NewLine + "}" + Environment.NewLine).Replace(",", "," + Environment.NewLine));

                    }

                    bMoreTasks = !string.IsNullOrEmpty(tasks.NextPageToken);
                    pageToken = tasks.NextPageToken;

                }

            }

            Console.ReadLine();

        }

    }

}
